#include "pgquery.h"

using namespace Porridge;

PGQuery::PGQuery(const std::string & connectionInfo, PGQueryQueue * queryQueue) :
    m_connection(PQconnectdb(connectionInfo.c_str())),
    m_queryQueue(queryQueue)
{
    if (PQstatus(m_connection) != CONNECTION_OK)
        ;// FIXME!!!
}

PGQuery::~PGQuery()
{
    if(m_connection)
        PQfinish(m_connection);
}

void PGQuery::performQuery()
{
    PGResult res = PQexec(m_connection, m_query.c_str());
    if (PQresultStatus(res) != PGRES_TUPLES_OK)
        ;//FIXME!!!

    //job done, ready for reuse
    //return ourself to thread pool
    m_queryQueue->push(this);
}
